<cfparam name="Workshop_Volunteer_ID" type="integer" default="0" />
<cfparam name="returnView" type="string" default="workshops" />
<cfparam name="passback" type="string" default="" />

<cfscript>
	workshopVolunteerGateway = new assets.calgrants.com.gateway.WorkshopVolunteerGateway();
	workshopVolunteer = workshopVolunteerGateway.get(Workshop_Volunteer_ID = Workshop_Volunteer_ID);
</cfscript>

<cfif IsNumeric(workshopVolunteer.getWorkshop_Volunteer_ID())>

	<cfscript>
		base = new assets.calgrants.com.Base();
		passbackQueryString = base.passbackToQueryString(passback);
		workshopGateway = new assets.calgrants.com.gateway.WorkshopGateway();
		workshop = workshopGateway.get(Workshop_ID = workshopVolunteer.getWorkshop_ID());
		siteGateway = new assets.calgrants.com.gateway.SiteGateway();
		site = siteGateway.get(Site_ID = workshop.getSite_ID());
		workshops = workshopGateway.query(regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), Organization_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""), Program_Year = request.currentProgramYear);
		volunteerGateway = new assets.calgrants.com.gateway.VolunteerGateway();
		volunteer = volunteerGateway.get(Volunteer_ID = workshopVolunteer.getVolunteer_ID());
		volunteers = volunteerGateway.query(regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), Organization_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""));
	</cfscript>
	
	<script type="text/javascript" language="javascript">
	<!--
		<cfoutput>
			var workshopID = #workshopVolunteer.getWorkshop_ID()#;
			var volunteerID = #workshopVolunteer.getVolunteer_ID()#;
			var workshops = new kendo.data.DataSource();
			workshops.data(#SerializeJSON(base.QueryToStruct(workshops), false)#);
			var volunteers = new kendo.data.DataSource();
			volunteers.data(#SerializeJSON(base.QueryToStruct(volunteers), false)#);
		</cfoutput>
		
		validate = function() {
			isValid = true;
			errorMessages = [];
			/*
			if (!$("#Online").is(":checked")) {
				var offlineReasons = $("#workshopForm")[0].Offline_Reasons;
				var offlineReasonChecked = false;
				for (var i=0; i < offlineReasons.length; i++) {
					if (offlineReasons[i].checked) {
						offlineReasonChecked = true;
						break;
					}
				}
				if (!offlineReasonChecked) {
					isValid = false;
					errorMessages.push("Indicate why you cannot have a computer-based workshop");
				}
				if ($("#offlineReasonOther").is(":checked")) {
					if ($("#offlineReasonsOtherDescription").val().length == 0) {
						isValid = false;
						errorMessages.push("Describe the other reason why you cannot have a computer based workshop in the field provided");
					}
				}
			}
			if ($("#Alt_Language_Workshop").is(":checked")) {
				if ($("#Alt_Languages").val().length == 0) {
					isValid = false;
					errorMessages.push("List alternate language workshop languages");
				}
			}
			if ($("#Translators").is(":checked")) {
				if ($("#Translator_Languages").val().length == 0) {
					isValid = false;
					errorMessages.push("List the translator languages");
				}
			}
			if ($("#Other_Services").is(":checked")) {
				if ($("#Other_Services_Description").val().length == 0) {
					isValid = false;
					errorMessages.push("List the other services");
				}
			}
			*/
			if (errorMessages.length > 0) {
				var errorMessage = "";
				for (var i=0; i<errorMessages.length; i++) {
					errorMessage += errorMessages[i] + "\n";	
				}
				alert(errorMessage);
			}
			return isValid;				
		}
		
		$(function() {
			$("#workshopVolunteerModal").modal();
			resizeModal("workshopVolunteerModal");
			var workshopDropDownList = $("#Workshop_ID").kendoDropDownList({
				dataTextField: "site",
				dataValueField: "workshop_id",
				dataSource: workshops,
				template: 	'<strong>${site}</strong><br>' +
							'${workshop_date} ${start_time}-${end_time}'
			}).data("kendoDropDownList");
			workshopDropDownList.value(workshopID);
			var volunteerDropDownList = $("#Volunteer_ID").kendoDropDownList({
				dataTextField: "full_name",
				dataValueField: "volunteer_id",
				dataSource: volunteers,
				template: 	'<strong>${full_name}</strong><br>' +
							'${address}<br>' + 
							'${city}, CA ${zip_code}'
			}).data("kendoDropDownList");
			volunteerDropDownList.value(volunteerID);
			if (!$("#Translator").is(":checked")) {
				$("#translatorLanguagesContainer").hide();
			}
		})
	//-->
	</script>
	
	<cfoutput>
	
		<cfform id="workshopVolunteerForm" name="workshopVolunteerForm" action="#script_name#" method="post" onsubmit="return validate();">
			<cfinput type="hidden" name="action" value="saveWorkshopVolunteer" />
			<cfinput type="hidden" name="view" value="#returnView#" />
			<cfinput type="hidden" name="Workshop_Volunteer_ID" value="#workshopVolunteer.getWorkshop_Volunteer_ID()#" />
			<cfif IsDefined("passback")>
				<cfloop index="keyValue" list="#passback#" delimiters=";">
					<cfinput type="hidden" name="#ListFirst(keyValue)#" value="#ListLast(keyValue)#" />
				</cfloop>
			</cfif>
			
			<div id="workshopVolunteerModal" class="modal modal-fullscreen" data-backdrop="static">
				<div class="modal-header">
					<h3>Workshop Volunteer</h3>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<div class="row-fluid">
							<div class="span4">
								<div class="clearfix">
									<label class="required">Confirmed</label>
									<cfselect name="Confirmed" required="yes" message="Confirmed is required" class="span9">
										<option value="0"<cfif workshopVolunteer.getConfirmed() eq 0> selected</cfif>>No</option>
										<option value="1"<cfif workshopVolunteer.getConfirmed() eq 1> selected</cfif>>Yes</option>
									</cfselect>
								</div>
								<div class="clearfix">
									<label class="required">Acknowledged</label>
									<cfselect name="Acknowledged" required="yes" message="Acknowledged is required" class="span9">
										<option value="0"<cfif workshopVolunteer.getAcknowledged() eq 0> selected</cfif>>No</option>
										<option value="1"<cfif workshopVolunteer.getAcknowledged() eq 1> selected</cfif>>Yes</option>
									</cfselect>
								</div>
								<div class="kendo-control clearfix" style="display: #IIf(workshopVolunteer.getWorkshop_ID() gt 0, DE('hidden'), DE('block'))#">
									<label class="required">Workshop</label>
									<cfinput type="text" id="Workshop_ID" name="Workshop_ID" required="yes" message="Workshop is required" style="width: 74.4681%" />
								</div>
								<!--- <cfif workshopVolunteer.getWorkshop_ID() gt 0>
									<div class="text-control clearfix">
										<label>Workshop</label>
										#site.getSite()#<br />
										#workshop.getWorkshop_Date()# #workshop.getStart_Time()#-#workshop.getEnd_Time()#<br />
										#site.getAddress()#<br />
										#site.getCity()#, CA #site.getZip_Code()#
									</div>
								</cfif> --->
								<cfif IsUserInRole("Super User") OR IsUserInRole("Regional_Admin")>
									<div class="kendo-control clearfix">
										<label class="required">Source Organization</label>
										<cfselect name="Organization_ID" required="yes" message="Organization is required" class="span9" style="margin: 0;"></cfselect>
									</div>
								<cfelse>
									<cfinput type="hidden" name="Organization_ID" value="#volunteer.getOrganization_ID()#">
									<!--- <div class="text-control clearfix">
										<label>Source</label>
										<cfif volunteer.getOrganization_ID() eq 0>
											Pool
										<cfelse>
											Registered
										</cfif>		
									</div> --->									
								</cfif>
							</div>
							<div class="span4">
								<cfif workshopVolunteer.getVolunteer_ID() eq 0>
									<div class="kendo-control clearfix" style="display: #IIf(workshopVolunteer.getVolunteer_ID() gt 0, DE('hidden'), DE('block'))#">
										<label class="required">Volunteer</label>
										<cfinput type="text" id="Volunteer_ID" name="Volunteer_ID" required="yes" message="Volunteer is required" style="width: 74.4681%" />
									</div>
								<cfelse>
									<div class="clearfix">
										<label class="required">First Name</label>
										<cfinput type="text" name="First_Name" value="#volunteer.getFirst_Name()#" required="yes" message="First Name is required" maxlength="50" class="span9">
									</div>
									<div class="clearfix">
										<label class="required">Last Name</label>
										<cfinput type="text" name="Last_Name" value="#volunteer.getLast_Name()#" required="yes" message="Last Name is required" maxlength="50" class="span9">
									</div>
									<div class="clearfix">
										<label>Organization/Company</label>
										<cfinput type="text" name="Organization" value="#volunteer.getOrganization()#" required="no" maxlength="100" class="span9">
									</div>
									<div class="clearfix">
										<label>Title</label>
										<cfinput type="text" name="Title" value="#volunteer.getTitle()#" required="no" maxlength="100" class="span9">
									</div>
									<div class="clearfix">
										<label class="required">E-mail</label>
										<cfinput type="text" name="Email" value="#volunteer.getEmail()#" required="yes" message="E-mail is required and must be a valid e-mail address" validate="email" maxlength="100" class="span9">
									</div>
									<div class="clearfix">
										<label class="required">Phone</label>
										<cfinput type="text" name="Phone" value="#volunteer.getPhone()#" required="yes" message="Phone is required and must be a valid telephone number" maxlength="15" validate="telephone" class="span9"><!---  <cfinput type="text" name="Extension" value="#user.getExtension()#" required="no" maxlength="10" placeholder="Extension" class="span3"> --->
									</div>
								</cfif>
							</div>
							<div class="span4">
								<cfif volunteer.getVolunteer_ID() gt 0>
									<!--- <div class="text-control clearfix">
										<label>Volunteer</label>
										#volunteer.getFirst_Name()# #volunteer.getLast_Name()#<br />
										<cfif Len(Trim(volunteer.getOrganization())) gt 0>
											#volunteer.getOrganization()#<br />
										</cfif>
										<cfif Len(Trim(volunteer.getTitle())) gt 0>
											#volunteer.getTitle()#<br />
										</cfif>
										#volunteer.getAddress()#<br />
										#volunteer.getCity()#, CA #volunteer.getZip_Code()#<br />
										#volunteer.getEmail()#<br />
										#volunteer.getPhone()#
										<!--- <cfdump var="#volunteer#" expand="no"> --->
									</div> --->
									
									<div class="clearfix">
										<label class="required">Travel Distance</label>
										<cfinput type="text" name="Email" value="#volunteer.getTravel_Distance()#" required="yes" message="Travel Distance is required and must be a whole number" validate="integer" maxlength="5" class="span9"> miles
									</div>
									<div class="text-control clearfix">
										<label>Shirt Size</label>
										<cfselect name="Shirt_Size" required="yes" message="Shirt Size is required" class="span9">
											<option value="">Select...</option>
											<option value="S"<cfif volunteer.getShirt_Size() eq "S"> selected</cfif>>Small</option>
											<option value="M"<cfif volunteer.getShirt_Size() eq "M"> selected</cfif>>Medium</option>
											<option value="L"<cfif volunteer.getShirt_Size() eq "L"> selected</cfif>>Large</option>
											<option value="XL"<cfif volunteer.getShirt_Size() eq "XL"> selected</cfif>>X-Large</option>
											<option value="XXL"<cfif volunteer.getShirt_Size() eq "XXL"> selected</cfif>>XX-Large</option>
										</cfselect>
									</div>
									<div class="text-control clearfix">
										<label>Specialties/Expertise</label>
								
										<div class="well well-small" style="line-height: 24px;">
											<label class="checkbox">
												<input type="checkbox" name="Student" value="1"<cfif volunteer.getStudent()> checked</cfif>>
												Student
											</label>
											<label class="checkbox">
												<input type="checkbox" name="Financial_Aid_Expert" value="1"<cfif volunteer.getFinancial_Aid_Expert()> checked</cfif>>
												Financial aid expert
											</label>
											<label class="checkbox">
												<input type="checkbox" name="FAFSA_Expert" value="1"<cfif volunteer.getFAFSA_Expert()> checked</cfif>>
												FAFSA expert
											</label>
											<label class="checkbox">
												<input type="checkbox" name="AB540_Expert" value="1"<cfif volunteer.getAB540_Expert()> checked</cfif>>
												CA Dream Act/AB540 expert
											</label>
											<label class="checkbox">
												<input type="checkbox" name="Finance_Expert" value="1"<cfif volunteer.getFinance_Expert()> checked</cfif>>
												Finance expert
											</label>
											<label class="checkbox">
												<input type="checkbox" name="Tax_Expert" value="1"<cfif volunteer.getTax_Expert()> checked</cfif>>
												Tax expert
											</label>
											<label class="checkbox">
												<input type="checkbox" name="Outreach_Expert" value="1"<cfif volunteer.getOutreach_Expert()> checked</cfif>>
												Outreach expert
											</label>
											<label class="checkbox">
												<input type="checkbox" name="Technology_Expert" value="1"<cfif volunteer.getTechnology_Expert()> checked</cfif>>
												Technology expert
											</label>
											<label class="checkbox">
												<input type="checkbox" id="Translator" name="Translator" value="1" onclick="toggle('Translator')"<cfif volunteer.getTranslator()> checked</cfif>>
												Translator
											</label>
											<div id="translatorLanguagesContainer">
												<cfinput type="text" id="Translator_Languages" name="Translator_Languages" value="#volunteer.getTranslator_Languages()#" class="span9" />
											</div>
										</div>
									</div>
								</cfif>
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a href="?view=#returnView#&#passbackQueryString#" class="btn">Cancel</a>
					<a class="btn" href="?action=deleteWorkshopVolunteer&view=#returnView#&Workshop_Volunteer_ID=#workshopVolunteer.getWorkshop_Volunteer_ID()#">Delete</a>
					<cfinput type="submit" name="saveButton" class="btn" value="Save" />
				</div>
			</div>
		</cfform>
		
	</cfoutput>

<cfelse>

	<div class="alert alert-info notFound">Workshop volunteer not found or insufficient permissions to perform this operation</div>

</cfif>
